package com.frxuexi.task.viewmodel

import com.frxuexi.lib_base.BaseViewModel
import com.frxuexi.task.intent.TaskIntent
import com.frxuexi.task.repository.TaskRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@HiltViewModel
class TaskViewModel @Inject constructor(private val taskRepository: TaskRepository):BaseViewModel<TaskIntent>() {
    override fun handleIntent(it: TaskIntent) {
        when(it){
            is TaskIntent.commitTask->{
                roomRequest(taskRepository.commitTask(it.task))
            }
            is TaskIntent.getTasks->{
                roomRequest(taskRepository.getTasks() as Flow<Any>)
            }
            is TaskIntent.approveTask->{
                roomRequest(taskRepository.approveTask(it.task))
            }
            else->{}
        }
    }
}